package com.wswy.wzcx.module.base

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.che.libcommon.ui.BaseActivity
import com.che.libcommon.ui.loading.LoadingActivity
import com.wswy.wzcx.R

abstract class CBaseLoadingActivity : LoadingActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    protected fun <T: ViewModel> provideViewModel(modelClass:Class<T>):T{
        return ViewModelProviders.of(this).get(modelClass)
    }

    protected val tvTitle:TextView? by lazy {
        findViewById<View>(R.id.img_back)?.let {
            it.setOnClickListener {
                onClickBack(it)
            }
        }?:kotlin.run {
            findViewById<View>(R.id.img_close)?.let {
                it.setOnClickListener {
                    onClickBack(it)
                }
            }
        }


        findViewById<TextView>(R.id.tv_title)
    }


    protected fun setAppTitle(title:CharSequence?){
        tvTitle?.text = title
    }

    protected open fun onClickBack(view:View){
        finish()
    }
}